package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.ExperimentRecord;
import com.ruoyi.business.service.IExperimentRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 实验记录Controller
 * 
 * @author qiancheng
 * @date 2025-06-13
 */
@Api(tags = "实验记录管理")
@RestController
@RequestMapping("/business/record")
public class ExperimentRecordController extends BaseController
{
    @Autowired
    private IExperimentRecordService experimentRecordService;

    /**
     * 查询实验记录列表
     */
    @ApiOperation("查询实验记录列表")
    @PreAuthorize("@ss.hasPermi('business:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("实验记录查询条件") ExperimentRecord experimentRecord)
    {
        startPage();
        List<ExperimentRecord> list = experimentRecordService.selectExperimentRecordList(experimentRecord);
        return getDataTable(list);
    }

    /**
     * 导出实验记录列表
     */
    @ApiOperation("导出实验记录列表")
    @PreAuthorize("@ss.hasPermi('business:record:export')")
    @Log(title = "实验记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ApiParam("实验记录查询条件") ExperimentRecord experimentRecord)
    {
        List<ExperimentRecord> list = experimentRecordService.selectExperimentRecordList(experimentRecord);
        ExcelUtil<ExperimentRecord> util = new ExcelUtil<ExperimentRecord>(ExperimentRecord.class);
        util.exportExcel(response, list, "实验记录数据");
    }

    /**
     * 获取实验记录详细信息
     */
    @ApiOperation("获取实验记录详细信息")
    @PreAuthorize("@ss.hasPermi('business:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam("实验记录ID") @PathVariable("id") Long id)
    {
        return success(experimentRecordService.selectExperimentRecordById(id));
    }

    /**
     * 新增实验记录
     */
    @ApiOperation("新增实验记录")
    @PreAuthorize("@ss.hasPermi('business:record:add')")
    @Log(title = "实验记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam("实验记录信息") @RequestBody ExperimentRecord experimentRecord)
    {
        return toAjax(experimentRecordService.insertExperimentRecord(experimentRecord));
    }

    /**
     * 修改实验记录
     */
    @ApiOperation("修改实验记录")
    @PreAuthorize("@ss.hasPermi('business:record:edit')")
    @Log(title = "实验记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("实验记录信息") @RequestBody ExperimentRecord experimentRecord)
    {
        return toAjax(experimentRecordService.updateExperimentRecord(experimentRecord));
    }

    /**
     * 删除实验记录
     */
    @ApiOperation("删除实验记录")
    @PreAuthorize("@ss.hasPermi('business:record:remove')")
    @Log(title = "实验记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("实验记录ID数组") @PathVariable Long[] ids)
    {
        return toAjax(experimentRecordService.deleteExperimentRecordByIds(ids));
    }
}
